package com.neusoft.elmboot.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.elmboot.po.PointLog;
import com.neusoft.elmboot.service.PointLogService;

@RestController
@RequestMapping("/PointLogController")
@CrossOrigin
public class PointLogController {

    @Autowired
    PointLogService pointLogService;

    // // 某个用户增加count分的log
    // @PostMapping("/points/{userId}")
    // public int savePointLog(@PathVariable String userId, @RequestBody PointLog pl, Integer count) throws Exception {
    //     pointLogService.savePointLog(pl);
    //     return count;
    // }

    // 查询当前时刻某用户的所有有效积分
    @GetMapping("/points/{userId}")
    public int getPointLogByUserIdByTime(@PathVariable String userId) throws Exception {
        return pointLogService.getPointLogByUserIdByTime(userId);
    }

    // 某个用户用掉count分
    @PutMapping("/points/{userId}")
    public int deletePointLogByUserIdByTime(@PathVariable String userId, @RequestBody Integer count) throws Exception {
        return pointLogService.deletePointLogByUserIdByTime(userId, count);
    }

    // 删去某个用户已过期的积分
    @DeleteMapping("/points/{userId}")
    public int updatePointLog(@PathVariable String userId) throws Exception {
        return pointLogService.updatePointLog(userId);
    }

    // 查询某个用户过期的积分数量
    @GetMapping("/points/expiration/{userId}")
    public int getExpirationPointLogByUserId(@PathVariable String userId) throws Exception {
        return pointLogService.getExpirationPointLogByUserId(userId);
    }

    
}